package leetcode;

public class 搜索旋转排序数组33 {

    public int search(int[] nums, int target) {
        int low = 0;
        int high = nums.length - 1;
        while (low<=high) {
            int mid = (low + high) / 2;
            if(target == nums[mid]) {
                return mid;
            }else if(nums[low] <= nums[mid]) {
                if(nums[low] <= target && target < nums[mid]) {
                    high = mid - 1;
                } else {
                    low = mid + 1;
                }
            } else if(nums[low] > nums[mid]) {
                if(target > nums[mid] && target <= nums[high]) {
                    low = mid + 1;
                } else {
                    high = mid - 1;
                }
            }
        }
        return -1;
    }

    public static void main(String[] args) {

    }
}
